//
//  CreateJobReviewSummaryView.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/16.
//

import UIKit
import SnapKit
class CreateJobReviewSummaryView: View {
    let titleView = CreateJobReviewSectionView(R.string.localizable.summary().uppercased(),haveEditBtnFlag: true)
    let companyText = CreateJobReviewContentLabel()
    let agentText = CreateJobReviewContentLabel()
    let tradeModeText = CreateJobReviewContentLabel()
    let poReferenceText = CreateJobReviewContentLabel()
    override func setUpView() {
        //titleView
        self.addSubview(titleView)
        titleView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        //company
        let companyTitle = CreateJobReviewTitleLabel(R.string.localizable.company())
        //抗压缩能力优先级高
        companyTitle.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        
        self.addSubview(companyTitle)
        companyTitle.snp.makeConstraints { make in
            make.top.equalTo(titleView.snp.bottom).offset(16)
            make.left.equalTo(16)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        companyText.numberOfLines = 0
        companyText.textAlignment = .right
        self.addSubview(companyText)
        companyText.snp.makeConstraints { make in
            make.left.equalTo(companyTitle.snp.right).offset(5)
            make.top.equalTo(companyTitle)
            make.right.equalTo(-16)
            make.height.greaterThanOrEqualTo(companyTitle)
        }
        //agent
        let agentTitle = CreateJobReviewTitleLabel(R.string.localizable.agent())
        //抗压缩能力优先级高
        agentTitle.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.addSubview(agentTitle)
        agentTitle.snp.makeConstraints { make in
            make.top.equalTo(companyText.snp.bottom).offset(CREATEJOB_REVIEW_INTERNAL)
            make.left.equalTo(companyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        agentText.numberOfLines = 0
        agentText.textAlignment = .right
        self.addSubview(agentText)
        agentText.snp.makeConstraints { make in
            make.top.equalTo(agentTitle)
            make.left.equalTo(agentTitle.snp.right).offset(5)
            make.right.equalTo(companyText)
            make.height.greaterThanOrEqualTo(agentTitle)
        }
        //trade mode
        let tradeModeTitle = CreateJobReviewTitleLabel(R.string.localizable.tradeMode())
        //抗压缩能力优先级高
        tradeModeTitle.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.addSubview(tradeModeTitle)
        tradeModeTitle.snp.makeConstraints { make in
            make.top.equalTo(agentText.snp.bottom).offset(CREATEJOB_REVIEW_INTERNAL)
            make.left.equalTo(companyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        tradeModeText.numberOfLines = 0
        tradeModeText.textAlignment = .right
        self.addSubview(tradeModeText)
        tradeModeText.snp.makeConstraints { make in
            make.top.equalTo(tradeModeTitle)
            make.left.equalTo(tradeModeTitle.snp.right).offset(5)
            make.right.equalTo(companyText)
            make.height.greaterThanOrEqualTo(tradeModeTitle)
        }
        //po reference
        let poReferenceTitle = CreateJobReviewTitleLabel(R.string.localizable.poReference())
        //抗压缩能力优先级高
        poReferenceTitle.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.addSubview(poReferenceTitle)
        poReferenceTitle.snp.makeConstraints { make in
            make.top.equalTo(tradeModeText.snp.bottom).offset(CREATEJOB_REVIEW_INTERNAL)
            make.left.equalTo(companyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        poReferenceText.numberOfLines = 0
        poReferenceText.textAlignment = .right
        self.addSubview(poReferenceText)
        poReferenceText.snp.makeConstraints { make in
            make.top.equalTo(poReferenceTitle)
            make.left.equalTo(poReferenceTitle.snp.right).offset(5)
            make.right.equalTo(companyText)
            make.height.greaterThanOrEqualTo(poReferenceTitle)
            make.bottom.equalTo(-16)
        }
    }
    func setData(){
        self.companyText.text = CreateJobModelHelper.shared.createJobViewModel.summaryViewModel.company_name
        self.agentText.text = CreateJobModelHelper.shared.createJobViewModel.summaryViewModel.agent_name
        let tradeMode = CreateJobModelHelper.shared.createJobViewModel.summaryViewModel.trade_mode
        if tradeMode == .credit {
            self.tradeModeText.text = R.string.localizable.oswCredit()
        }else if tradeMode == .cash {
            self.tradeModeText.text = R.string.localizable.cash()
        }
        self.poReferenceText.text = CreateJobModelHelper.shared.createJobViewModel.summaryViewModel.customer_po
    }
}
